// Copyright Rachael Colley 2013.

package rach.grid.andgrid1;

import java.util.Map;
import java.util.TreeMap;


public class BuildEmptyGrid {

	private int countZ = 0;
	private int countY = 0;
	private int countX = 0;

	public BuildEmptyGrid() {

	}

	public Map<Integer,Map<Integer,Map<Integer,GridCell>>> buildZMap(WorldParameters wp) {
		int minZ = wp.getMinGridZ();
		int maxZ = wp.getMaxGridZ();
		int minY = wp.getMinGridY();
		int maxY = wp.getMaxGridY();
		int minX = wp.getMinGridX();
		int maxX = wp.getMaxGridX();
		return buildZMap(minZ,maxZ,minY,maxY,minX,maxX);
	}

	private Map<Integer,Map<Integer,Map<Integer,GridCell>>> buildZMap(int minZ, int maxZ, int minY, int maxY, int minX, int maxX) {
		Map<Integer,Map<Integer,Map<Integer,GridCell>>> zMap = new TreeMap<Integer,Map<Integer,Map<Integer,GridCell>>>();
		for (int xCounter = minZ; xCounter < maxZ + 1; xCounter ++) {
			zMap.put(xCounter, buildYMap(minY,maxY,minX,maxX));
			countZ ++;
		}
		writeToLog();
		return zMap;
	}

	private Map<Integer,Map<Integer,GridCell>> buildYMap(int minY,int maxY, int minX, int maxX) {
		Map<Integer,Map<Integer,GridCell>> yMap = new TreeMap<Integer,Map<Integer,GridCell>>();
		for (int xCounter = minY; xCounter < maxY + 1; xCounter ++){
			yMap.put(xCounter, buildXMap(minX,maxX));
			countY ++;
		}
		return yMap;
	}

	private Map<Integer,GridCell> buildXMap(int minX, int maxX) {
		Map<Integer,GridCell> xMap = new TreeMap<Integer,GridCell>();
		for(int xCounter = minX; xCounter < maxX + 1; xCounter ++) {
			xMap.put(xCounter,null);
			countX ++;
		}
		return xMap;
	}
	
	private void writeToLog() {
		String z = ("\nNumber of ZMap entries: " + countZ);
		String y = ("\nNumber of YMap entries: " + countY);
		String x = ("\nNumber of XMap entries: " + countX);
		//writeLogs.writeLine(z+y+x);
	}


}
